/**
 * @ClassName BubbleSortTest
 * @Description TODO
 * @Author lwj
 * @Date 2021/5/9 15:49
 * @Version 1.0
 */
public class BubbleSortTest {
    public static void main(String[] args) {
        int[] arr = new int[]{9, 3, 5, 2, 4, 6, 1, 8, 7};
        for (int i = 0; i < arr.length; i++) {
            boolean hasSwitch = false;
            for (int j = 0; j < arr.length - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    hasSwitch = true;
                }
            }
            if (!hasSwitch) {
                break;
            }
            for (int k : arr) {
                System.out.print(k + "\t");
            }
            System.out.println();
        }
    }
}
